package com.liangzong.betspider.executor;

import com.liangzong.betspider.command.AddTeamInfoCMD;
import com.liangzong.betspider.command.GameOverStateCMD;
import com.liangzong.betspider.entity.TeamInfo;
import com.liangzong.betspider.enums.CommandEnum;
import com.liangzong.betspider.service.TeamInfoService;
import com.liangzong.betspider.service.TeamPointService;
import com.liangzong.betspider.service.TeamScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
public class GameOverStateExecutor implements Executor<GameOverStateCMD> {

    @Autowired
    TeamInfoService teamInfoService;

    @Autowired
    TeamPointService teamPointService;

    @Autowired
    TeamScoreService teamScoreService;

    @Override
    public boolean support(CommandEnum commandEnum) {
        return commandEnum == CommandEnum.GAMEOVER;
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void process(GameOverStateCMD command) {
        log.info(command.getTeamInfo().toString());
        TeamInfo teamInfo = command.getTeamInfo();
        if(teamInfo!=null) {
            teamInfoService.update(teamInfo);
        }
    }
}
